package com.hao.springboot02web.config;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;

public class LoginHandleInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object session = request.getSession().getAttribute("loginUsername");
        if (session!=null){
            return true;
        }else {
            request.setAttribute("msg","无权限，请重新登录!");
            request.getRequestDispatcher("/index.html").forward(request,response);
            return false;
        }
    }
}
